package com.zengqingfa.examples.mybatisplus.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zengqingfa.examples.mybatisplus.entity.UserHistory;
import com.zengqingfa.examples.mybatisplus.response.Result;
import com.zengqingfa.examples.mybatisplus.service.UserHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @fileName: UserHistoryController
 * @author: zengqf3
 * @date: 2021-3-2 14:59
 * @description:
 */
@RestController
@RequestMapping("/userHistory")
@Slf4j
public class UserHistoryController {

    @Autowired
    private UserHistoryService userHistoryService;

    @PostMapping("/page")
    public Result page(@RequestBody UserHistory userHistory, @RequestParam("pageNo") Integer pageNo,
            @RequestParam("pageSize") Integer pageSize) {
        Page<UserHistory> page = new Page<>(pageNo, pageSize);
        QueryWrapper wrapper=new QueryWrapper(userHistory);
        IPage page1 = userHistoryService.page(page, wrapper);
        return Result.success(page1);
    }

    @PostMapping("/selectById")
    public Result selectById(@RequestParam("id") Long id) {
        UserHistory userHistory = userHistoryService.selectById(id);
        return Result.success(userHistory);
    }
}
